/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.refunite.mobile.s60.widget;

import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import org.javarosa.core.model.QuestionDef;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;

/**
 *
 * @author I040022
 */
public class AbstractFormWidget extends Form{
    protected FormEntryPrompt formEntryPrompt;
    protected FormEntryController formEntryController;
    protected int questionIndex;
    protected boolean initialized = false;

    public AbstractFormWidget(FormEntryController formEntryController, FormEntryPrompt formEntryPrompt, int index){
        super("");
        this.formEntryController = formEntryController;
        this.formEntryPrompt = formEntryPrompt;
        this.questionIndex = index;
        this.setTitle(this.formEntryController.getModel().getFormTitle());
        QuestionDef def = this.formEntryPrompt.getQuestion();
        String title = def.getLongText();
        String help = def.getHelpText();
        if(title == null) title = "";
        if(help == null) help = "";
        StringItem titleItem = new StringItem(null, title);
        StringItem helpItem = new StringItem(help, null);
        titleItem.setLayout(StringItem.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_VCENTER | Item.LAYOUT_EXPAND | Item.LAYOUT_2 | Item.LAYOUT_NEWLINE_AFTER);
        helpItem.setLayout(StringItem.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_VCENTER | Item.LAYOUT_EXPAND | Item.LAYOUT_2 | Item.LAYOUT_NEWLINE_AFTER);
        this.append(titleItem);
        this.append(helpItem);

    }

    public int getIndexOfQuestion(){
        return this.questionIndex;
    }

    public void saveAnswer() {
    }

    public void initialize(){
        this.initialized = true;
    }

    public boolean getInitialized(){
        return this.initialized;
    }
}
